package com.ss.summer.entity;


import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 组织
 * </p>
 *
 * @author xia17
 * @since 2019-07-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SummerGroup implements Serializable {

private static final long serialVersionUID=1L;


    private Long id;

    /**
     * 组名
     */
    private String name;

    /**
     * 组名备注
     */
    private String remark;

    /**
     * 上一个组织
     */
    private Long lastGroup;

    /**
     * 在源数据表中的Id(在指定组审核时会用到)
     */
    private String sourceId;

    private List<SummerGroup> sonGroups;

    /**
     * 将所有子组添加成一个List
     * @return
     */
    public List<SummerGroup> getAllGroupList(){
        ArrayList<SummerGroup> result = new ArrayList<>();
        this.addToList(this,result);
        return result;
    }


    private void addToList(SummerGroup group, List<SummerGroup> result){
        result.add(group);
        List<SummerGroup> sonGroups = group.getSonGroups();
        if (sonGroups == null){
            return;
        }
        for (SummerGroup sonGroup : sonGroups) {
            this.addToList(sonGroup,result);
        }
    }



}
